package metalink;

import com.opensymphony.xwork2.ActionSupport;

import java.sql.Time;
import java.sql.Timestamp;
import java.util.Date;
import java.util.*;
import java.sql.*;

import org.apache.struts2.ServletActionContext;


import vo.*;
import vo.mixed.*;
import model.admin.*;
import model.GroupsMo;
import myutil.*;

import java.io.*;

import javax.servlet.http.HttpSession;

public class ShowGroups extends ActionSupport{
	BeanGroupDetails bean_group_details;
	int user_id, group_id, grp_id, group_update_id, cool = 0, agree=0, c_cool_count, c_agree_count, updater_id, group_member_count;
	String group_name, last_update_date, create_date, owner_id, addcomment, group_wall_post, email_id, member_id;
	ArrayList<BeanGroupDetails> groups_by_owner;
	ArrayList<BeanGroupDetails> groups;
	ArrayList<BeanGroupMember> group_members;
	ArrayList<BeanGroupUpdates> group_updates;
	ArrayList<BeanGroupUpdates> comment, wall_post;
	ArrayList<BeanGroupUpdatesComplete> all_updates;
	BeanGroupUpdates header;
	HttpSession sessioncheck;
	HttpSession session;
	public String getAllGroups(){
		sessioncheck = ServletActionContext.getRequest().getSession();
		GroupsMo groupsmo = new GroupsMo();
		try{
			groups_by_owner = new ArrayList<BeanGroupDetails>();
			groups = new ArrayList<BeanGroupDetails>();
			String username=ServletActionContext.getRequest().getSession().getAttribute("username").toString();
			user_id = groupsmo.getUserIdMo(username);
			groups = groupsmo.getGroupsMo(user_id);
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 	ERROR;
		}
	}
	
	
	
	public String getGroupDetails(){
		session = ServletActionContext.getRequest().getSession();
		GroupsMo groupsmo = new GroupsMo();
		groups = new ArrayList<BeanGroupDetails>();
		group_members = new ArrayList<BeanGroupMember>();
		all_updates = new ArrayList<BeanGroupUpdatesComplete>();
		try{
			BeanGroupDetails bgd = groupsmo.getGroupDetailsMo(group_id);
			groups.add(bgd);
			group_members = groupsmo.getGroupMembersMo(group_id);
			group_member_count = group_members.size();
			all_updates = groupsmo.getGroupUpdatesMo(group_id);
			session.setAttribute("group_id", group_id);
			session.setAttribute("groupupdates", "main");
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
		
	}
	
	public String getGroupAllUpdates(){
		session = ServletActionContext.getRequest().getSession();
		GroupsMo groupsmo = new GroupsMo();
		//groups = new ArrayList<BeanGroupDetails>();
		//group_members = new ArrayList<BeanGroupMember>();
		all_updates = new ArrayList<BeanGroupUpdatesComplete>();
		try{
			int grp_id = (int) session.getAttribute("group_id");
			//BeanGroupDetails bgd = groupsmo.getGroupDetailsMo(group_id);
			//groups.add(bgd);
			//group_members = groupsmo.getGroupMembersMo(group_id);
			all_updates = groupsmo.getGroupUpdatesMo(grp_id);
			//session.setAttribute("group_id", group_id);
			session.setAttribute("groupupdates", "post_update");
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
		
	}
	
	public String addMember(){
		GroupsMo groupsmo = new GroupsMo();
		group_members = new ArrayList<BeanGroupMember>();
		try{
			groupsmo.addMemberMo(email_id, group_id);
			group_members = groupsmo.getGroupMembersMo(group_id);
			group_member_count = group_members.size();
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
	}
	
	public String deleteMember(){
		session = ServletActionContext.getRequest().getSession();
		GroupsMo groupsmo = new GroupsMo();
		group_members = new ArrayList<BeanGroupMember>();
		try{
			int grp_id = (int) session.getAttribute("group_id");
			groupsmo.deleteMemberMo(email_id);
			group_members = groupsmo.getGroupMembersMo(grp_id);
			group_member_count = group_members.size();
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
	}
	
	public String addComments(){
		GroupsMo groupsmo = new GroupsMo();
		comment = new ArrayList<BeanGroupUpdates>();
		try{
			groupsmo.addCommentMo(group_update_id, addcomment);
			comment = groupsmo.CommentsMo(group_update_id);
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
	}
	
	public String groupWallPost(){
		session = ServletActionContext.getRequest().getSession();
		GroupsMo groupsmo = new GroupsMo();
		groups = new ArrayList<BeanGroupDetails>();
		group_members = new ArrayList<BeanGroupMember>();
		all_updates = new ArrayList<BeanGroupUpdatesComplete>();
		
		//wall_post = new ArrayList<BeanGroupUpdates>();
		try{
			int group_update_id = groupsmo.groupWallPostMo(group_wall_post);
			//wall_post = groupsmo.getUpdateMo(group_update_id);
			
			int grp_id = (int) session.getAttribute("group_id");
			System.out.println(grp_id);
			BeanGroupDetails bgd = groupsmo.getGroupDetailsMo(grp_id);
			groups.add(bgd);
			group_members = groupsmo.getGroupMembersMo(grp_id);
			all_updates = groupsmo.getGroupUpdatesMo(grp_id);
			session.setAttribute("groupupdates", "post_update");
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
	}
	
	
	public String Comments(){
		GroupsMo groupsmo = new GroupsMo();
		comment = new ArrayList<BeanGroupUpdates>();
		try{
			comment = groupsmo.CommentsMo(group_update_id);
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
	}
	
	public String coolComment(){
		GroupsMo groupsmo = new GroupsMo();
		comment = new ArrayList<BeanGroupUpdates>();
		try{
			groupsmo.coolCommentMo(group_update_id);
			comment = groupsmo.CommentsMo(group_update_id);
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
	}
	
	public String agreeComment(){
		GroupsMo groupsmo = new GroupsMo();
		comment = new ArrayList<BeanGroupUpdates>();
		try{
			groupsmo.agreeCommentMo(group_update_id);
			comment = groupsmo.CommentsMo(group_update_id);
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
	}
	
	public String deleteComment(){
		GroupsMo groupsmo = new GroupsMo();
		comment = new ArrayList<BeanGroupUpdates>();
		try{
			groupsmo.deleteCommentMo(group_update_id);
			comment = groupsmo.CommentsMo(group_update_id);
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
	}
	
	public String cool(){
		session = ServletActionContext.getRequest().getSession();
		GroupsMo groupsmo = new GroupsMo();
		//groups = new ArrayList<BeanGroupDetails>();
		//group_members = new ArrayList<BeanGroupMember>();
		all_updates = new ArrayList<BeanGroupUpdatesComplete>();
		try{
			groupsmo.coolMo(group_update_id);
			//BeanGroupDetails bgd = groupsmo.getGroupDetailsMo(group_id);
			//groups.add(bgd);
			//group_members = groupsmo.getGroupMembersMo(group_id);
			int grp_id = (int) session.getAttribute("group_id");
			all_updates = groupsmo.getGroupUpdatesMo(grp_id);
			session.setAttribute("groupupdates", "post_update");
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
	}
	
	public String deletePost(){
		session = ServletActionContext.getRequest().getSession();
		all_updates = new ArrayList<BeanGroupUpdatesComplete>();
		GroupsMo groupsmo = new GroupsMo();
		try{
			groupsmo.deletePostMo(group_update_id);
			int grp_id = (int) session.getAttribute("group_id");
			all_updates = groupsmo.getGroupUpdatesMo(grp_id);
			session.setAttribute("groupupdates", "post_update");
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
	}
	
	public String agree(){
		session = ServletActionContext.getRequest().getSession();
		GroupsMo groupsmo = new GroupsMo();
		//groups = new ArrayList<BeanGroupDetails>();
		//group_members = new ArrayList<BeanGroupMember>();
		all_updates = new ArrayList<BeanGroupUpdatesComplete>();
		try{
			groupsmo.agreeMo(group_update_id);
			int grp_id = (int) session.getAttribute("group_id");
			//BeanGroupDetails bgd = groupsmo.getGroupDetailsMo(group_id);
			//groups.add(bgd);
			//group_members = groupsmo.getGroupMembersMo(group_id);
			all_updates = groupsmo.getGroupUpdatesMo(grp_id);
			session.setAttribute("groupupdates", "post_update");
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
	}

	public ArrayList<BeanGroupDetails> getGroups_by_owner() {
		return groups_by_owner;
	}

	public void setGroups_by_owner(ArrayList<BeanGroupDetails> groups_by_owner) {
		this.groups_by_owner = groups_by_owner;
	}

	public ArrayList<BeanGroupMember> getGroup_members() {
		return group_members;
	}

	public void setGroup_members(ArrayList<BeanGroupMember> group_members) {
		this.group_members = group_members;
	}

	public int getUser_id() {
		return user_id;
	}

	public void setUser_id(int user_id) {
		this.user_id = user_id;
	}

	public ArrayList<BeanGroupDetails> getGroups() {
		return groups;
	}

	public void setGroups(ArrayList<BeanGroupDetails> groups) {
		this.groups = groups;
	}

	public int getGroup_id() {
		return group_id;
	}

	public void setGroup_id(int group_id) {
		this.group_id = group_id;
	}


	public String getGroup_name() {
		return group_name;
	}

	public void setGroup_name(String group_name) {
		this.group_name = group_name;
	}

	public String getLast_update_date() {
		return last_update_date;
	}

	public void setLast_update_date(String last_update_date) {
		this.last_update_date = last_update_date;
	}

	public String getCreate_date() {
		return create_date;
	}

	public void setCreate_date(String create_date) {
		this.create_date = create_date;
	}

	public String getOwner_id() {
		return owner_id;
	}

	public void setOwner_id(String owner_id) {
		this.owner_id = owner_id;
	}

	public HttpSession getSessioncheck() {
		return sessioncheck;
	}

	public void setSessioncheck(HttpSession sessioncheck) {
		this.sessioncheck = sessioncheck;
	}

	public BeanGroupDetails getBean_group_details() {
		return bean_group_details;
	}

	public void setBean_group_details(BeanGroupDetails bean_group_details) {
		this.bean_group_details = bean_group_details;
	}

	public ArrayList<BeanGroupUpdates> getGroup_updates() {
		return group_updates;
	}

	public void setGroup_updates(ArrayList<BeanGroupUpdates> group_updates) {
		this.group_updates = group_updates;
	}

	public BeanGroupUpdates getHeader() {
		return header;
	}

	public void setHeader(BeanGroupUpdates header) {
		this.header = header;
	}

	public ArrayList<BeanGroupUpdatesComplete> getAll_updates() {
		return all_updates;
	}

	public void setAll_updates(ArrayList<BeanGroupUpdatesComplete> all_updates) {
		this.all_updates = all_updates;
	}

	public int getGrp_id() {
		return grp_id;
	}

	public void setGrp_id(int grp_id) {
		this.grp_id = grp_id;
	}

	public HttpSession getSession() {
		return session;
	}

	public void setSession(HttpSession session) {
		this.session = session;
	}

	public int getGroup_update_id() {
		return group_update_id;
	}

	public void setGroup_update_id(int group_update_id) {
		this.group_update_id = group_update_id;
	}

	public int getCool() {
		return cool;
	}

	public void setCool(int cool) {
		this.cool = cool;
	}

	public int getAgree() {
		return agree;
	}

	public void setAgree(int agree) {
		this.agree = agree;
	}

	public void setComment(ArrayList<BeanGroupUpdates> comment) {
		this.comment = comment;
	}

	public ArrayList<BeanGroupUpdates> getComment() {
		return comment;
	}

	public int getC_cool_count() {
		return c_cool_count;
	}

	public void setC_cool_count(int c_cool_count) {
		this.c_cool_count = c_cool_count;
	}

	public int getC_agree_count() {
		return c_agree_count;
	}

	public void setC_agree_count(int c_agree_count) {
		this.c_agree_count = c_agree_count;
	}

	public String getAddcomment() {
		return addcomment;
	}

	public void setAddcomment(String addcomment) {
		this.addcomment = addcomment;
	}

	public int getUpdater_id() {
		return updater_id;
	}

	public void setUpdater_id(int updater_id) {
		this.updater_id = updater_id;
	}

	public String getGroup_wall_post() {
		return group_wall_post;
	}

	public void setGroup_wall_post(String group_wall_post) {
		this.group_wall_post = group_wall_post;
	}

	public ArrayList<BeanGroupUpdates> getWall_post() {
		return wall_post;
	}

	public void setWall_post(ArrayList<BeanGroupUpdates> wall_post) {
		this.wall_post = wall_post;
	}



	public String getEmail_id() {
		return email_id;
	}



	public void setEmail_id(String email_id) {
		this.email_id = email_id;
	}



	public int getGroup_member_count() {
		return group_member_count;
	}



	public void setGroup_member_count(int group_member_count) {
		this.group_member_count = group_member_count;
	}



	public String getMember_id() {
		return member_id;
	}



	public void setMember_id(String member_id) {
		this.member_id = member_id;
	}
}
